package org.xg.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author CMG
 * @version 1.0
 * @description 通过注解设置Servlet初始化参数
 * @cLassName MyServlet
 * @date 2021/9/23 10:39
 **/
@WebServlet(urlPatterns = {"/myConfig"}, initParams = {@WebInitParam(name = "name", value = "xg"),
        @WebInitParam(name = "URL", value = "www.ocmg.top")})
public class MyServletConfig extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 设置响应给页面的格式、字符集
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.write("hello world");
        writer.close();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
